home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / trem.zip / COMEVENT.C < prev    next >
Text File  |  1991-05-11  |  4KB  |  154 lines

  1. /************************************************************************
  2.  *
  3.  *    Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *-----------------------------------------------------------------------
  6.  *
  7.  *     Project:  Windows Terminal Example
  8.  *
  9.  *      Module:  comevent.c
  10.  *
  11.  *      Author:  Bryan A. Woodruff (baw)
  12.  *
  13.  *
  14.  *     Remarks:  Comm Event Timer Stuff
  15.  *
  16.  *   Revisions:  
  17.  *     01.00.000  5/ 9/91 baw   Wrote it
  18.  *
  19.  ************************************************************************/
  20.  
  21. #include "terminal.h"
  22.  
  23. /************************************************************************
  24.  *  BOOL SetEvent( HWND hWnd, int nCid, WORD wEventMask )
  25.  *
  26.  *  Description:
  27.  *     Creates an event in the event structure.  If the same event
  28.  *     has already been flagged, this routine returns TRUE.
  29.  *
  30.  *  Comments:
  31.  *      5/ 9/91  baw  Wrote it
  32.  *
  33.  ************************************************************************/
  34.  
  35. BOOL SetEvent( HWND hWnd, int nCid, WORD wEventMask, WORD wMsg )
  36. {
  37.    int i ;
  38.  
  39.    if (!nIdTimer)
  40.    {
  41.       lpTimerProc = MakeProcInstance( TimerHandler, hAppInst ) ;
  42.       nIdTimer = SetTimer( NULL, TIMER_EVENT, TIMER_INTERVAL,
  43.                            lpTimerProc ) ;
  44.       if (!nIdTimer)
  45.          return ( FALSE ) ;
  46.    }
  47.  
  48.    // if same event already exists, just return TRUE
  49.  
  50.    for (i = 0; i < MAXEVENTS; i++)
  51.       if (aEvents[i].hWnd == hWnd &&
  52.           aEvents[i].nCid == nCid &&
  53.           aEvents[i].wEventMask == wEventMask)
  54.          return ( TRUE ) ;
  55.  
  56.    // find empty spot in events list
  57.  
  58.    for (i = 0; i < MAXEVENTS; i++)
  59.    {
  60.       if (aEvents[i].hWnd == NULL)
  61.       {
  62.          aEvents[i].nCid = nCid ;
  63.          aEvents[i].wEventMask = wEventMask ;
  64.          aEvents[i].lpEventPtr = SetCommEventMask( nCid, wEventMask ) ;
  65.          aEvents[i].wMsg = wMsg ;
  66.          aEvents[i].fPostFlag = FALSE ;
  67.          aEvents[i].hWnd = hWnd ;
  68.          return ( TRUE ) ;
  69.       }
  70.    }
  71.    return ( FALSE ) ;
  72.    
  73. } /* end of SetEvent() */
  74.  
  75. /************************************************************************
  76.  *  VOID KillEvent( HWND hWnd, int nCid, WORD wEventMask )
  77.  *
  78.  *  Description:
  79.  *     Removes event from event list.
  80.  *
  81.  *  Comments:
  82.  *      5/ 8/91  baw  Wrote it.
  83.  *
  84.  ************************************************************************/
  85.  
  86. VOID KillEvent( HWND hWnd, int nCid, WORD wEventMask )
  87. {
  88.    int  i ;
  89.  
  90.    for (i = 0; i < MAXEVENTS; i++)
  91.    {
  92.       if (aEvents[i].hWnd == hWnd &&
  93.           aEvents[i].nCid == nCid &&
  94.           aEvents[i].wEventMask == wEventMask)
  95.       {
  96.          aEvents[i].hWnd = NULL ;
  97.          aEvents[i].nCid = 0 ;
  98.          aEvents[i].fPostFlag = FALSE ;
  99.          aEvents[i].wEventMask = 0 ;
  100.          aEvents[i].wMsg = NULL ;
  101.          aEvents[i].lpEventPtr = NULL ;
  102.          break;
  103.       }
  104.    }
  105.  
  106.    // if no events in the list, kill the system timer
  107.  
  108.    for (i=0; i < MAXEVENTS; i++)
  109.       if (aEvents[i].hWnd != NULL)
  110.          return ;
  111.  
  112.    KillTimer( NULL, nIdTimer ) ;
  113.    FreeProcInstance( lpTimerProc ) ;
  114.    lpTimerProc = NULL ;
  115.    nIdTimer = 0 ;
  116.  
  117.    return ;
  118.  
  119. } /* end of KillEvent() */
  120.  
  121. /************************************************************************
  122.  *  BOOL ClearEvent( HWND hWnd, int nCid, WORD wEventMask )
  123.  *
  124.  *  Description:
  125.  *     Clears the post flag for the given event.
  126.  *
  127.  *  Comments:
  128.  *      5/ 8/91  baw  Wrote it.
  129.  *
  130.  ************************************************************************/
  131.  
  132. BOOL ClearEvent( HWND hWnd, int nCid, WORD wEventMask )
  133. {
  134.    int  i ;
  135.  
  136.    for (i = 0; i < MAXEVENTS; i++)
  137.    {
  138.       if (aEvents[i].hWnd == hWnd &&
  139.           aEvents[i].nCid == nCid &&
  140.           aEvents[i].wEventMask == wEventMask)
  141.       {
  142.          aEvents[i].fPostFlag = FALSE ;
  143.          return ( TRUE ) ;
  144.       }
  145.    }
  146.    return ( FALSE ) ;
  147.  
  148. } /* end of ClearEvent() */
  149.  
  150. /************************************************************************
  151.  * End of File: comevent.c
  152.  ************************************************************************/
  153.  
  154.